import { PropType, ExtractPropTypes } from 'vue'

export function booleanType(defaultVal?: boolean) {
  return { type: Boolean, default: defaultVal as boolean };
}

export type Type =
  | 'horizontal'
  | 'vertical'

interface Tree {
  label: string;
  className: string;
  children: Tree[];
}
interface Button {
  radius: string | number;
}

const orgTreeProps = {
  direction: {
    type: String as PropType<Type>,
    validator: (val: string) => {
      // 自定义校验器
      return [
        'horizontal',
        'vertical',
      ].includes(val)
    },
    default: 'horizontal'
  },
  treeData: Array as PropType<Tree[]>,
  button: Object as PropType<Partial<Button>>,
  bordered: booleanType(),
} as const;

export default orgTreeProps;
export type OrgTreeProps = ExtractPropTypes<typeof orgTreeProps>;